package iqiyi;


import java.util.*;

public class Main1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String str = sc.nextLine();
			int nums[] = new int[6];
			int arr_1[] = new int[6];
			int arr_2[] = new int[6];
			for(int i = 0; i < 6; i++) {
				nums[i] = str.charAt(i) - '0';
				arr_1[i] = nums[i] - 0;
				arr_2[i] = 9 - nums[i];
			}
			int sum1 = nums[0]+nums[1]+nums[2];
			int sum2 = nums[3]+nums[4]+nums[5];
			int dis = sum2 - sum1;
			int ress = 0;
			Arrays.sort(arr_1, 0, 3);
			Arrays.sort(arr_2, 0, 3);
			Arrays.sort(arr_1, 3, 6);
			Arrays.sort(arr_2, 3, 6);

			if (dis > 0) {
				for(int i = 2, j = 5; i >= 0 && j >= 3;) {
					if(dis <= 0) break;
					ress += 1;
					if(dis <= Math.max(arr_1[j], arr_2[i])) break;
					else dis -= Math.max(arr_1[j], arr_2[i]);
					if (arr_1[i] >= arr_2[j]) i--;
					else j--;
				}
			}
			else if (dis < 0) {
				dis = -dis;
				for(int i = 2, j = 5; i >= 0 && j >= 3;) {
					if(dis <= 0) break;
					ress += 1;
					if(dis <= Math.max(arr_1[i], arr_2[j])) break;
					else dis -= Math.max(arr_1[i], arr_2[j]);
					if (arr_1[i] >= arr_2[j]) i--;
					else j--;
				}
			}
			System.out.println(ress);
		}
	}

}

